View Javadoc
1 /************************************************************ 2 * Copyright * 3 * Portions of this software are Copyright (c) 1993 - 2002, * 4 * Chad Z. Hower (Kudzu) and the Indy Pit Crew * 5 * - http://www.nevrona.com/Indy/ * 6 ************************************************************/ 7 package org.indy; 8 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.Collections; 12 import java.util.Iterator; 13 import java.util.List; 14 import java.util.ListIterator; 15 16 17 /*** 18 * A specialized collection class for {@link IdCommnandHandler} 19 * 20 * This class is not thread safe without external sync. 21 * 22 *@author OTG 23 */ 24 public class CommandHandlers implements List { 25 private final TCPServer server; 26 private final List commandHandlers = Collections.synchronizedList( 27 new ArrayList()); 28 29 /*** 30 * Constructs a new IdCommandHandlers collection. 31 * 32 *@param server The server instance that owns this collection. 33 */ 34 public CommandHandlers(TCPServer server) { 35 this.server = server; 36 } 37 38 /*** 39 * DOCUMENT ME! 40 * 41 * @return DOCUMENT ME! 42 */ 43 public boolean isEmpty() { 44 return commandHandlers.isEmpty(); 45 } 46 47 /*** 48 * Returns the {@link IdCommandHandler} instance at <code>index</code> 49 * 50 *@param index The index of the reuiqred handler. 51 *@return The IdCommandHandler at <code>index</code> 52 *@throws IndexOutOfBoundsException if <code>index</code> is invalid. 53 */ 54 public CommandHandler getCommandHandler(int index) { 55 boundsCheck(index); 56 57 return (CommandHandler) commandHandlers.get(index); 58 } 59 60 /*** 61 * Returns the {@link IdTCPServer} that owns this collection. 62 * 63 *@return The IdTCPServer for this collection. 64 */ 65 public TCPServer getServer() { 66 return server; 67 } 68 69 private void boundsCheck(int index) { 70 if ((index < 0) || (index > commandHandlers.size())) { 71 throw new IndexOutOfBoundsException(); 72 } 73 } 74 75 /*** 76 * Adds an {@link IdCommandHandler} to this collection. 77 * 78 *@param ch The IdCommandHandler to add. 79 */ 80 public void add(CommandHandler ch) { 81 commandHandlers.add(ch); 82 } 83 84 /*** 85 * Adds an {@link IdCommandHandler} to this collection at the specified index. 86 * 87 *@param ch The IdCommandHandler to add. 88 *@param index The index to add at. 89 *@throws IndexOutOfBoundsException If index is invalid. 90 */ 91 public void add(CommandHandler ch, int index) { 92 boundsCheck(index); 93 commandHandlers.add(index, ch); 94 } 95 96 /*** 97 * Returns the number of elements in this collection. 98 * 99 *@return The number of elements in this collection. 100 */ 101 public int size() { 102 return commandHandlers.size(); 103 } 104 105 /*** 106 * DOCUMENT ME! 107 * 108 * @param o DOCUMENT ME! 109 * 110 * @return DOCUMENT ME! 111 */ 112 public boolean contains(Object o) { 113 return commandHandlers.contains(o); 114 } 115 116 /*** 117 * DOCUMENT ME! 118 * 119 * @return DOCUMENT ME! 120 */ 121 public Iterator iterator() { 122 return commandHandlers.iterator(); 123 } 124 125 /*** 126 * DOCUMENT ME! 127 * 128 * @return DOCUMENT ME! 129 */ 130 public Object[] toArray() { 131 return commandHandlers.toArray(); 132 } 133 134 /*** 135 * DOCUMENT ME! 136 * 137 * @param a DOCUMENT ME! 138 * 139 * @return DOCUMENT ME! 140 */ 141 public Object[] toArray(Object[] a) { 142 return commandHandlers.toArray(a); 143 } 144 145 /*** 146 * DOCUMENT ME! 147 * 148 * @param o DOCUMENT ME! 149 * 150 * @return DOCUMENT ME! 151 */ 152 public boolean add(Object o) { 153 return commandHandlers.add(o); 154 } 155 156 /*** 157 * DOCUMENT ME! 158 * 159 * @param o DOCUMENT ME! 160 * 161 * @return DOCUMENT ME! 162 */ 163 public boolean remove(Object o) { 164 return commandHandlers.remove(o); 165 } 166 167 /*** 168 * DOCUMENT ME! 169 * 170 * @param c DOCUMENT ME! 171 * 172 * @return DOCUMENT ME! 173 */ 174 public boolean containsAll(Collection c) { 175 return commandHandlers.containsAll(c); 176 } 177 178 /*** 179 * DOCUMENT ME! 180 * 181 * @param c DOCUMENT ME! 182 * 183 * @return DOCUMENT ME! 184 */ 185 public boolean addAll(Collection c) { 186 return commandHandlers.addAll(c); 187 } 188 189 /*** 190 * DOCUMENT ME! 191 * 192 * @param index DOCUMENT ME! 193 * @param c DOCUMENT ME! 194 * 195 * @return DOCUMENT ME! 196 */ 197 public boolean addAll(int index, Collection c) { 198 return commandHandlers.addAll(index, c); 199 } 200 201 /*** 202 * DOCUMENT ME! 203 * 204 * @param c DOCUMENT ME! 205 * 206 * @return DOCUMENT ME! 207 */ 208 public boolean removeAll(Collection c) { 209 return commandHandlers.removeAll(c); 210 } 211 212 /*** 213 * DOCUMENT ME! 214 * 215 * @param c DOCUMENT ME! 216 * 217 * @return DOCUMENT ME! 218 */ 219 public boolean retainAll(Collection c) { 220 return commandHandlers.retainAll(c); 221 } 222 223 /*** 224 * DOCUMENT ME! 225 */ 226 public void clear() { 227 commandHandlers.clear(); 228 } 229 230 /*** 231 * DOCUMENT ME! 232 * 233 * @param o DOCUMENT ME! 234 * 235 * @return DOCUMENT ME! 236 */ 237 public boolean equals(Object o) { 238 return commandHandlers.equals(o); 239 } 240 241 /*** 242 * DOCUMENT ME! 243 * 244 * @param index DOCUMENT ME! 245 * 246 * @return DOCUMENT ME! 247 */ 248 public Object get(int index) { 249 return commandHandlers.get(index); 250 } 251 252 /*** 253 * DOCUMENT ME! 254 * 255 * @param index DOCUMENT ME! 256 * @param element DOCUMENT ME! 257 * 258 * @return DOCUMENT ME! 259 */ 260 public Object set(int index, Object element) { 261 return commandHandlers.set(index, element); 262 } 263 264 /*** 265 * DOCUMENT ME! 266 * 267 * @param index DOCUMENT ME! 268 * @param element DOCUMENT ME! 269 */ 270 public void add(int index, Object element) { 271 commandHandlers.add(index, element); 272 } 273 274 /*** 275 * DOCUMENT ME! 276 * 277 * @param index DOCUMENT ME! 278 * 279 * @return DOCUMENT ME! 280 */ 281 public Object remove(int index) { 282 return commandHandlers.remove(index); 283 } 284 285 /*** 286 * DOCUMENT ME! 287 * 288 * @param o DOCUMENT ME! 289 * 290 * @return DOCUMENT ME! 291 */ 292 public int indexOf(Object o) { 293 return commandHandlers.indexOf(o); 294 } 295 296 /*** 297 * DOCUMENT ME! 298 * 299 * @param o DOCUMENT ME! 300 * 301 * @return DOCUMENT ME! 302 */ 303 public int lastIndexOf(Object o) { 304 return commandHandlers.lastIndexOf(o); 305 } 306 307 /*** 308 * DOCUMENT ME! 309 * 310 * @return DOCUMENT ME! 311 */ 312 public ListIterator listIterator() { 313 return commandHandlers.listIterator(); 314 } 315 316 /*** 317 * DOCUMENT ME! 318 * 319 * @param index DOCUMENT ME! 320 * 321 * @return DOCUMENT ME! 322 */ 323 public ListIterator listIterator(int index) { 324 return commandHandlers.listIterator(index); 325 } 326 327 /*** 328 * DOCUMENT ME! 329 * 330 * @param fromIndex DOCUMENT ME! 331 * @param toIndex DOCUMENT ME! 332 * 333 * @return DOCUMENT ME! 334 */ 335 public List subList(int fromIndex, int toIndex) { 336 return commandHandlers.subList(fromIndex, toIndex); 337 } 338 }

This page was automatically generated by Maven